home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / sys / mass.lha / Mass.S < prev   
Text File  |  1995-04-17  |  5KB  |  262 lines

  1. ;##############################################################################
  2. ;
  3. ; $VER: MASS_source 1.1.017 (13.4.1995) Rudla Kudla
  4. ;
  5. ;##############################################################################
  6.  
  7. ;TestInput
  8.  
  9. ERROR_NODOSLIB    =20
  10.  
  11.         INCDIR    "INCLUDES:"
  12.         INCLUDE    "exec/macros.i"
  13.         INCLUDE    "exec/exec_lib.i"
  14.         INCLUDE    "dos/dos_lib.i"
  15.         INCLUDE    "dos/dos.i"    
  16.  
  17. LINE        equr    a2
  18. BUFFER        equr    a3
  19. ASSNAME        equr    d5
  20. SPACE        equr    d6
  21. TYPE        equr    d7
  22.  
  23.         IFD    TestInput
  24.         ;In real input, we will get $A ended string in a0 and it's
  25.         ;lenght (+1 for $A) in d0. This is simulated here for testing.
  26.  
  27.         lea    Test(pc),a0
  28.         move.l    #EndTest-Test,d0
  29.         ENDC
  30.  
  31. ;======    Allocate local variables on stack, init input line and some registers
  32.  
  33.         move.l    a0,LINE
  34.         clr.b    -1(a0,d0.w)        ;zero end input string
  35.         moveq    #' ',SPACE
  36.  
  37. ;======    Open Dos library
  38.  
  39.         move.l    4.w,a6
  40.         lea    dos_name(pc),a1
  41.         moveq    #36,d0
  42.         JSRLIB    OpenLibrary
  43.         move.l    d0,a6
  44.         tst.l    d0
  45.         bne.b    .dos_ok
  46.         moveq    #ERROR_NODOSLIB,d0
  47.         rts
  48.  
  49. ;------    This code is called from different places to exit (closes dos.library)
  50.  
  51. .end
  52.         move.l    a6,a1
  53.         move.l    4.w,a6
  54.         JSRLIB    CloseLibrary
  55.         moveq    #0,d0
  56.         rts
  57. .dos_ok
  58.  
  59. ;======    Read string (it can be command, assign name or directory path)
  60.  
  61. .LIST        equr    a4
  62. .RESULT        equr    d2
  63.  
  64.         moveq    #0,.RESULT
  65. .command    move.l    .RESULT,TYPE
  66. .lock
  67.         bsr.w    GetString        ;read first word
  68.         beq.b    .end
  69.  
  70. ;======    Test, if this is command (compare it with list of commands)
  71.  
  72.         lea    command_list(pc),.LIST
  73.         moveq    #2,.RESULT
  74.         bra.b    .test_list_end
  75.         
  76. .compare_list    move.l    BUFFER,a0
  77. .compare_item    tst.b    (.LIST)
  78.         beq.b    .command
  79.         move.b    (a0)+,d0
  80.         or.b    SPACE,d0
  81.         cmp.b    (.LIST)+,d0
  82.         beq.b    .compare_item
  83.  
  84. .next_item    tst.b    (.LIST)+
  85.         bne.b    .next_item
  86.         addq.w    #2,.RESULT
  87.  
  88. .test_list_end    tst.b    (.LIST)
  89.         bne.b    .compare_list
  90.  
  91. ;======    This is not an command, so it must be assign name or path
  92. ;    If it is ended with ":", it is assign name, otherwise it is directory
  93. ;    path.
  94.  
  95. .not_command
  96.         moveq    #":",d0
  97.         cmp.b    -2(LINE),d0        ;assign name ends with ":"
  98.         beq.b    .double
  99.         moveq    #8,TYPE            ;makedir type
  100.         bra.b    .makedir
  101. .double
  102.         clr.b    -2(LINE)
  103.         move.l    BUFFER,ASSNAME
  104.  
  105. ;====== Read path to assign and prepare values
  106.  
  107. .LOCK        equr    d4
  108.  
  109.         bsr.b    GetString
  110.         beq.b    .end
  111.         move.l    BUFFER,.LOCK
  112.         cmp.w    #4,TYPE
  113.         bhs.b    .lock_not_needed
  114. .makedir
  115.  
  116. ;======    Lock directory (if it does not exist, create all needed subdirs)
  117.  
  118. .LIMITER    equr    d3
  119. .DIREND        equr    a4
  120.  
  121.         moveq    #0,.LOCK
  122.         move.l    BUFFER,.DIREND
  123.         move.b    (.DIREND),.LIMITER
  124.  
  125. ;------    Find end of next directory name (if 0 is first char, end assign)
  126.  
  127. .next_dir
  128.         move.b    .LIMITER,(.DIREND)+
  129.         beq.b    .lock_done
  130. .first        move.b    (.DIREND)+,d0
  131.         beq.b    .found_dir
  132.         cmp.b    #'/',d0
  133.         bne.b    .first
  134. .found_dir    subq.w    #1,.DIREND
  135.  
  136. ;------    Next dir name was found, so unlock previous lock and cut new path
  137.  
  138.         move.b    (.DIREND),.LIMITER
  139.         clr.b    (.DIREND)
  140.  
  141. .unlock        move.l    .LOCK,d1
  142.         beq.b    .skip_unlock
  143.         JSRLIB    UnLock
  144. .skip_unlock        
  145.  
  146. ;------ Try to lock this directory (if sucesfull, try to nest into subdir)
  147.  
  148.         move.l    BUFFER,d1
  149.         moveq    #ACCESS_READ,d2
  150.         JSRLIB    Lock
  151.         move.l    d0,.LOCK
  152.         bne.b    .next_dir
  153.  
  154. ;------ Dir can't be locked, so we will create it and try to lock it again
  155.  
  156.         move.l    BUFFER,d1
  157.         JSRLIB    CreateDir
  158.         move.l    d0,.LOCK    ;returns exclusive lock if suceed
  159.         bne.b    .unlock
  160. .lock_done
  161.  
  162. .lock_not_needed
  163.  
  164. ;======    Parameters are prepared, so go and assign according to type
  165.  
  166.         move.l    ASSNAME,d1
  167.         move.l    .LOCK,d2
  168.         beq.b    .lock_failed
  169.         jsr    .Commands(PC,TYPE.w)
  170. .lock_failed    bra.w    .lock
  171. .Commands
  172.         bra.b    .AssNormal
  173.         bra.b    .AssAdd
  174.         bra.b    .AssDefer
  175.         bra.b    .AssPath
  176.         bra.b    .free_lock
  177.  
  178. .AssNormal
  179.         JSRLIB    AssignLock
  180. .test_success    tst.l    d0
  181.         bne.b    .success
  182. .free_lock    move.l    d2,d1
  183.         beq.b    .success
  184.         JSRLIB    UnLock
  185. .success    rts
  186. .AssAdd
  187.         JSRLIB    AssignAdd
  188.         bra.b    .test_success
  189. .AssDefer    JMPLIB    AssignLate
  190. .AssPath    JMPLIB    AssignPath
  191.  
  192.  
  193. GetString ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  194. ;IN:    LINE    input command line
  195. ;OUT:    LINE    point after last char of string
  196. ;    BUFFER    first character of string
  197. ;FUNC:    Finds string in source LINE and ends it with 0. String can be
  198. ;    enclosed in quotes or can't contain any spaces or tabs.
  199. ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  200.  
  201.         PUSHM    d0-d2
  202.  
  203.         moveq    #' ',d1
  204.         moveq    #9,d2
  205.  
  206. ;======    Skip empty characters (spaces and tabs)
  207.  
  208. .skip        move.l    LINE,BUFFER
  209.         move.b    (LINE)+,d0
  210.         beq.b    .end
  211.         cmp.b    d0,d1
  212.         beq.b    .skip
  213.         cmp.b    d0,d2
  214.         beq.b    .skip
  215.  
  216. ;======    Detect string begin and delimiters
  217.  
  218.         cmp.b    #34,-(LINE)    ;we know, that there is some char>0
  219.         bne.b    .find_end
  220.         addq.w    #1,LINE
  221.         moveq    #34,d1
  222.         moveq    #34,d2
  223.         
  224. ;======    Remember begin and find end of string
  225.  
  226. .find_end
  227.         move.l    LINE,BUFFER
  228.         bra.b    .test_end
  229.         
  230. ..        cmp.b    d0,d1
  231.         beq.b    .end
  232.         cmp.b    d0,d2
  233.         beq.b    .end
  234. .test_end    move.b    (LINE)+,d0
  235.         bne.b    ..
  236.  
  237. ;======    Change string delimiter to 0
  238.  
  239.         clr.b    -(LINE)
  240.         bra.b    .tst
  241. .end        clr.b    -1(LINE)
  242.  
  243. .tst        tst.b    (BUFFER)        ;test, if string is empty
  244.         POPM
  245.         rts
  246.  
  247. version_string    DC.B    "$VER: MASS 1.1 (14.4.1995) Rudla Kudla",0
  248. dos_name    DC.B    "dos.library",0
  249. command_list    DC.B    "add",0,"defer",0,"path",0,0
  250.  
  251.     IFD    TestInput
  252. Test
  253.     DC.B    "ram:dir1 ram:dir2/dir21 ram:dir1/dir11 "
  254. ;    DC.B    "memory: ram:mem add memory: ram:mem2 memory: ram:mem3 "
  255. ;    DC.B    "PATH "
  256. ;    DC.B    "EPSON: ",34,"Workbench:devs/new printer/epson",34," "
  257. ;    DC.B    "DEFER "
  258. ;    DC.B    "CANON: ",34,"Workbench:devs/new printer/canon",34
  259.     DC.B    $A
  260. EndTest
  261.         ENDC
  262.